<template xmlns:v-swiper="http://www.w3.org/1999/xhtml">
  <div>
    <!-- 幻灯片 开始 -->
    <el-carousel :interval="6000" type="card" height="380px">
      <el-carousel-item v-for="banner in bannerList" :key="banner.id">
        <a target="_blank" :href="banner.linkUrl">
          <el-image :src="banner.imageUrl" :alt="banner.title" class=".elcarousel-img"/>
        </a>
      </el-carousel-item>
    </el-carousel>
    <div id="aCoursesList">
      <!-- 幻灯片 结束 -->
      <!-- 网校课程 开始 -->
      <div>
        <section class="container">
          <header class="comm-title">
            <h2 class="tac">
              <span class="c-333">热门课程</span>
            </h2>
          </header>
          <div>
            <article class="comm-course-list">
              <ul class="of" id="bna">
                <!--开始遍历-->
                <li v-for="course in courseList" :key="course.id">
                  <div class="cc-l-wrap">
                    <section
                      class="course-img"
                      style="width: 270px; height: 180px"
                    >
                      <img
                        :src="course.cover"
                        class="img-responsive elcarousel-img"
                        :alt="course.title"
                      />
                      <div class="cc-mask">
                        <a
                          :href="'/course/' + course.id"
                          target="_blank"
                          title="查看详情"
                          class="comm-btn c-btn-1"
                          >查看详情</a
                        >
                      </div>
                    </section>
                    <h3 class="hLh30 txtOf mt10">
                      <a
                        :href="'/course/' + course.id"
                        target="_blank"
                        :title="course.title"
                        class="course-title fsize18 c-333"
                        >{{ course.title }}</a
                      >
                    </h3>
                    <section class="mt10 hLh20 of">
                      <span class="fl jgAttr c-ccc f-fA">
                        <i class="c-999 f-fA">{{ course.viewCount }}次浏览</i>
                        |
                        <i class="c-999 f-fA">{{ course.commentCount }}评论</i>
                        |
                        <i class="c-999 f-fA"
                          >发布于：{{ course.gmtCreate.substr(0, 10) }}</i
                        >
                      </span>
                    </section>
                  </div>
                </li>
                <!--遍历结束-->
              </ul>
              <div class="clear"></div>
            </article>
            <section class="tac pt20">
              <a href="/course" title="全部课程" class="comm-btn c-btn-2"
                >全部课程</a
              >
            </section>
          </div>
        </section>
      </div>
      <!-- /网校课程 结束 -->

      <!-- 网校名师 开始 -->
      <div>
        <section class="container">
          <header class="comm-title">
            <h2 class="tac">
              <span class="c-333">名师大咖</span>
            </h2>
          </header>
          <div>
            <article class="i-teacher-list">
              <ul class="of">
                <!--开始遍历讲师列表-->
                <li v-for="teacher in teacherList" :key="teacher.id">
                  <section class="i-teach-wrap">
                    <div class="i-teach-pic">
                      <a :href="'/teacher/' + teacher.id" :title="teacher.name">
                        <img :alt="teacher.name" :src="teacher.avatar" />
                      </a>
                    </div>
                    <div class="mt10 hLh30 txtOf tac">
                      <a
                        :href="'/teacher/' + teacher.id"
                        :title="teacher.name"
                        class="fsize18 c-666"
                        >{{ teacher.name }}</a
                      >
                    </div>
                    <div class="hLh30 txtOf tac">
                      <span class="fsize14 c-999">{{ teacher.intro }}</span>
                    </div>
                    <div class="mt15 i-q-txt">
                      <p class="c-999 f-fA">
                        {{ teacher.career }}
                      </p>
                    </div>
                  </section>
                </li>
                <!--遍历结束-->
              </ul>
              <div class="clear"></div>
            </article>
            <section class="tac pt20">
              <a href="/teacher" title="全部老师" class="comm-btn c-btn-2"
                >全部讲师</a
              >
            </section>
          </div>
        </section>
      </div>
      <!-- /网校名师 结束 -->
    </div>
  </div>
</template>

<script>
import banner from '@/api/banner'
import index from '@/api/index'
export default {
  data() {
    return {
      swiperOption: {
        //配置分页
        pagination: {
          el: '.swiper-pagination', //分页的dom节点
        },
        //配置导航
        navigation: {
          nextEl: '.swiper-button-next', //下一页dom节点
          prevEl: '.swiper-button-prev', //前一页dom节点
        },
      },
      bannerList: {}, //轮播图
      teacherList: {}, //首页讲师列表
      courseList: {}, // 首页课程列表
    }
  },

  created() {
    this.initDataBanner()
    this.initDataTeacherAndCourse()
  },
  methods: {
    initDataBanner() {
      banner.getAllBanner().then((response) => {
        this.bannerList = response.data.data.bannerList
      })
    },
    initDataTeacherAndCourse() {
      index.getIndexList().then((response) => {
        this.teacherList = response.data.data.teacherList
        this.courseList = response.data.data.courseList
      })
    },
  },
}
</script>

<style>
.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
.elcarousel-img{
  width:100%;
  height:100%;
}
</style>